﻿using System;
using System.ComponentModel;
using System.Linq.Expressions;
using NUnit.Framework;

namespace Present.Core.Tests.Extensions
{
    public static class NotifiableObjectTestExtensions
    {
        /// <summary>
        /// Asserts provided notifcation was fired when change action is executed.
        /// </summary>
        public static void AssertPropertyOnChangeEventFired<T>(this T parent, Expression<Func<T, object>> propertyExpression, Action changeProperty) where T : INotifyPropertyChanged
        {
            bool eventFired = false;
            var subscription = parent.WhenPropertyChanges(propertyExpression).Subscribe(e => eventFired = true);
            changeProperty();
            Assert.IsTrue(eventFired);
            subscription.Dispose();
        }
    }
}